package com.toutiao.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.base.entity.QueryParams;
import com.toutiao.dao.NewsCommentMapper;
import com.toutiao.dao.model.NewsComment;
import com.toutiao.dao.model.NewsCommentExample;
import com.toutiao.dao.model.NewsCommentReplyExample;
import com.toutiao.daoEx.NewsCommentMapperEx;
import com.toutiao.daoEx.model.NewsCommentEx;

@Service
public class NewsCommentService {
	@Autowired
	private NewsCommentMapper newsCommentMapper;
	@Autowired
	private NewsCommentMapperEx newsCommentMapperEx;

	@Autowired
	private NewsCommentReplyService newsCommentReplyService;

	public int countByExample(NewsCommentExample example) {
		return this.newsCommentMapper.countByExample(example);
	}

	public NewsComment selectByPrimaryKey(Integer id) {
		return this.newsCommentMapper.selectByPrimaryKey(id);
	}

	public List<NewsComment> selectByExample(NewsCommentExample example) {
		return this.newsCommentMapper.selectByExample(example);
	}

	public int deleteByPrimaryKey(Integer id) {
		Integer count = null;
		try{
			 count = this.newsCommentMapper.deleteByPrimaryKey(id);
			//删除评论时，该评论的所有回复一并被删除
			NewsCommentReplyExample newsCommentReplyExample = new NewsCommentReplyExample();
			newsCommentReplyExample.createCriteria().andCommentIdEqualTo(id);
			newsCommentReplyService.deleteByExample(newsCommentReplyExample);
		}catch (Exception e){
			e.printStackTrace();
		}
		return count;
	}

	public int updateByPrimaryKeySelective(NewsComment record) {
		return this.newsCommentMapper.updateByPrimaryKeySelective(record);
	}

	public int updateByPrimaryKey(NewsComment record) {
		return this.newsCommentMapper.updateByPrimaryKey(record);
	}

	public int deleteByExample(NewsCommentExample example) {
		return this.newsCommentMapper.deleteByExample(example);
	}

	public int updateByExampleSelective(NewsComment record, NewsCommentExample example) {
		return this.newsCommentMapper.updateByExampleSelective(record, example);
	}

	public int updateByExample(NewsComment record, NewsCommentExample example) {
		return this.newsCommentMapper.updateByExample(record, example);
	}

	public int insert(NewsComment record) {
		return this.newsCommentMapper.insert(record);
	}

	public int insertSelective(NewsComment record) {
		return this.newsCommentMapper.insertSelective(record);
	}
	
	public List<NewsCommentEx> selectAppList(QueryParams.Builder builder){
		return this.newsCommentMapperEx.selectAppList(builder);
	}

}
